package com.wxy.school.utils;

import jakarta.servlet.http.HttpSession;

import java.util.HashMap;

//存储监听器监听到的session
public class GetSessionId {
    private static GetSessionId instance;
    private final HashMap mymap;

    private GetSessionId() {
        mymap = new HashMap();
    }

    public static GetSessionId getInstance() {
        if (instance == null) {
            instance = new GetSessionId();
        }
        return instance;
    }

    public synchronized void AddSession(HttpSession session) {
        if (session != null) {
            mymap.put(session.getId(), session);
        }
    }

    public synchronized void DelSession(HttpSession session) {
        if (session != null) {
            mymap.remove(session.getId());
        }
    }

    public synchronized HttpSession getSession(String session_id) {
        if (session_id == null) return null;
        return (HttpSession) mymap.get(session_id);
    }

}

